From 0d2678417ceeef96fd58f834af727db3f33d9933 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Sun, 29 Apr 2007 18:13:42 +0000 Subject: [PATCH] New method to marshall and send a Startup Notification message. (from * gdk/x11/gdkdisplay-x11.c (gdk_x11_display_broadcast_startup_message): New method to marshall and send a Startup Notification message. (from #415070) (gdk_notify_startup_complete_with_id): Use that svn path=/trunk/; revision=17710 --- ChangeLog | 7 +++ gdk/x11/gdkdisplay-x11.c | 116 ++++++++++++++++++++++++--------------- gdk/x11/gdkx.h | 4 ++ 3 files changed, 83 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index 98f652bec1..a1af309b0f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2007-04-29 Dan Winship + + * gdk/x11/gdkdisplay-x11.c + (gdk_x11_display_broadcast_startup_message): New method to + marshall and send a Startup Notification message. (from #415070) + (gdk_notify_startup_complete_with_id): Use that + 2007-04-29 Mattthias Clasen * gtk/gtkprintoperation-unix.c diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c index ace29b2cfc..8beb889212 100644 --- a/gdk/x11/gdkdisplay-x11.c +++ b/gdk/x11/gdkdisplay-x11.c @@ -930,33 +930,6 @@ _gdk_windowing_set_default_display (GdkDisplay *display) } } -static char* -escape_for_xmessage (const char *str) -{ - GString *retval; - const char *p; - - retval = g_string_new (NULL); - - p = str; - while (*p) - { - switch (*p) - { - case ' ': - case '"': - case '\\': - g_string_append_c (retval, '\\'); - break; - } - - g_string_append_c (retval, *p); - ++p; - } - - return g_string_free (retval, FALSE); -} - static void broadcast_xmessage (GdkDisplay *display, const char *message_type, @@ -972,6 +945,9 @@ broadcast_xmessage (GdkDisplay *display, Atom type_atom_begin; Window xwindow; + if (!G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client)) + return; + { XSetWindowAttributes attrs; @@ -1045,6 +1021,72 @@ broadcast_xmessage (GdkDisplay *display, XFlush (xdisplay); } +/** + * gdk_x11_display_broadcast_startup_message: + * @display: a #GdkDisplay + * @message_type: startup notification message type ("new", "change", + * or "remove") + * @...: a list of key/value pairs (as strings), terminated by a + * %NULL key. (A %NULL value for a key will cause that key to be + * skipped in the output.) + * + * Sends a startup notification message of type @message_type to + * @display. + * + * This is a convenience function for use by code that implements the + * freedesktop startup notification specification. Applications should + * not normally need to call it directly. See the Startup + * Notification Protocol specification for + * definitions of the message types and keys that can be used. + * + * Since: 2.12 + **/ +void +gdk_x11_display_broadcast_startup_message (GdkDisplay *display, + const char *message_type, + ...) +{ + GString *message; + va_list ap; + const char *key, *value, *p; + + message = g_string_new (message_type); + g_string_append_c (message, ':'); + + va_start (ap, message_type); + while ((key = va_arg (ap, const char *))) + { + value = va_arg (ap, const char *); + if (!value) + continue; + + g_string_append_printf (message, " %s=\"", key); + for (p = value; *p; p++) + { + switch (*p) + { + case ' ': + case '"': + case '\\': + g_string_append_c (message, '\\'); + break; + } + + g_string_append_c (message, *p); + } + g_string_append_c (message, '\"'); + } + va_end (ap); + + broadcast_xmessage (display, + "_NET_STARTUP_INFO", + "_NET_STARTUP_INFO_BEGIN", + message->str); + + g_string_free (message, TRUE); +} + /** * gdk_notify_startup_complete: * @@ -1064,8 +1106,6 @@ gdk_notify_startup_complete (void) { GdkDisplay *display; GdkDisplayX11 *display_x11; - gchar *escaped_id; - gchar *message; display = gdk_display_get_default (); if (!display) @@ -1076,9 +1116,6 @@ gdk_notify_startup_complete (void) if (display_x11->startup_notification_id == NULL) return; - if (!G_LIKELY (display_x11->trusted_client)) - return; - gdk_notify_startup_complete_with_id (display_x11->startup_notification_id); } @@ -1101,23 +1138,14 @@ void gdk_notify_startup_complete_with_id (const gchar* startup_id) { GdkDisplay *display; - gchar *escaped_id; - gchar *message; display = gdk_display_get_default (); if (!display) return; - escaped_id = escape_for_xmessage (startup_id); - message = g_strdup_printf ("remove: ID=%s", escaped_id); - g_free (escaped_id); - - broadcast_xmessage (display, - "_NET_STARTUP_INFO", - "_NET_STARTUP_INFO_BEGIN", - message); - - g_free (message); + gdk_x11_display_broadcast_startup_message (display, "remove", + "ID", startup_id, + NULL); } /** diff --git a/gdk/x11/gdkx.h b/gdk/x11/gdkx.h index 9563e1b814..ec85047913 100644 --- a/gdk/x11/gdkx.h +++ b/gdk/x11/gdkx.h @@ -148,6 +148,10 @@ void gdk_x11_display_set_cursor_theme (GdkDisplay *display, const gchar *theme, const gint size); +void gdk_x11_display_broadcast_startup_message (GdkDisplay *display, + const char *message_type, + ...) G_GNUC_NULL_TERMINATED; + /* returns TRUE if we support the given WM spec feature */ gboolean gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen, GdkAtom property); -- 2.30.2